package org.phoenix.mall.admin.common.utils;

import org.apache.commons.io.FileUtils;
import org.phoenix.mall.admin.common.pojo.vo.RightVO;
import org.springframework.core.io.ClassPathResource;

import java.io.File;
import java.io.IOException;
import java.util.List;

public class BuildObjUtil {

    public static <T> List<T> build(String fileName, Class<T> cls) {
        ClassPathResource resource = new ClassPathResource(fileName);
        try {
            File file = resource.getFile();
            String json = FileUtils.readFileToString(file,"UTF-8");
            return JsonUtil.jsonToList(json, cls);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String[] args) {
        List<RightVO> list = build("data/rights.json",RightVO.class);
        System.out.println(list.size());
    }
}
